/*
 PureMVC AS3 Demo - Flex Application Skeleton 
 Copyright (c) 2007 Daniele Ugoletti <daniele.ugoletti@puremvc.org>
 Your reuse is governed by the Creative Commons Attribution 3.0 License
*/
package com.larson.creator
{
    import com.larson.creator.controller.*;
    import com.larson.creator.model.*;
    import com.larson.creator.view.*;
    import com.larson.creator.view.components.*;
    
    import org.puremvc.as3.interfaces.*;
    import org.puremvc.as3.patterns.facade.*;
    import org.puremvc.as3.patterns.proxy.*;

    /**
     * A concrete <code>Facade</code> for the <code>ApplicationSkeleton</code> application.
     * <P>
     * The main job of the <code>ApplicationFacade</code> is to act as a single 
     * place for mediators, proxies and commands to access and communicate
     * with each other without having to interact with the Model, View, and
     * Controller classes directly. All this capability it inherits from 
     * the PureMVC Facade class.</P>
     * 
     * <P>
     * This concrete Facade subclass is also a central place to define 
     * notification constants which will be shared among commands, proxies and
     * mediators, as well as initializing the controller with Command to 
     * Notification mappings.</P>
     */
    public class ApplicationFacade extends Facade
    {
        // Notification name constants
		// application
        public static const STARTUP:String 					= "startup";
        public static const SHUTDOWN:String 				= "shutdown";
		
		// proxy
        public static const LOADING_STEP:String				= "loadingStep";
        public static const LOADING_COMPLETE:String			= "loadingComplete";
		public static const LOAD_CONFIG_FAILED:String		= "loadConfigFailed";
        public static const LOAD_RESOURCE_FAILED:String		= "loadResourceFailed";
        
        public static const LOAD_FILE_COMPLETE:String		= "loadFileComplate";
        public static const CONVERT_FILE_COMPLETE:String	= "convertFileComplate";
        public static const DATA_READY:String 				= "DataReady";		
        
		// command
        public static const COMMAND_STARTUP_MONITOR:String	= "StartupMonitorCommand";
        public static const COMMAND_FILE_LOAD:String 		= "FileLoad";

        public static const COMMAND_FILE_CONVERT:String 	= "FileConvert";
		public static const COMMAND_ELEVATION_CORRECT:String = "elevationCorrection";  
		      		
		// view
		public static const VIEW_MAP_SCREEN:String		= "viewMapScreen";
		public static const VIEW_PROFILE_SCREEN:String	= "viewProfileScreen";
		public static const VIEW_COURSE_SCREEN:String	= "viewCourseScreen";
		public static const VIEW_DATA_SCREEN:String		= "viewDataScreen";
		public static const VIEW_BUILD_SCREEN:String	= "viewBuildScreen";			
		
		// common messages
		public static const ERROR_LOAD_FILE:String			= "Could Not Load the File!";
		
		public var application:CourseCreator;
		
        /**
         * Singleton ApplicationFacade Factory Method
         */
        public static function getInstance() : ApplicationFacade 
		{
            if ( instance == null ) instance = new ApplicationFacade( );
            return instance as ApplicationFacade;
        }

        /**
         * Register Commands with the Controller 
         */
        override protected function initializeController( ) : void 
        {
            super.initializeController(); 
            registerCommand( STARTUP, ApplicationStartupCommand );
            registerCommand( COMMAND_FILE_LOAD, LoadFileCommand );
            registerCommand( COMMAND_FILE_CONVERT, ConvertFileCommand );       
            registerCommand( COMMAND_ELEVATION_CORRECT, CorrectElevationCommand );        }		
		/**
         * Retrieve the config proxy 
         */
		public static function getConfigProxy():ConfigProxy
		{
			return ConfigProxy( ApplicationFacade.getInstance().retrieveProxy( ConfigProxy.NAME ) );
		}
    
		/**
         * Retrieve the resource proxy 
         */
		public static function getLocaleProxy():LocaleProxy
		{
			return LocaleProxy( ApplicationFacade.getInstance().retrieveProxy( LocaleProxy.NAME ) );
		}

		/**
         * Retrieve the File load proxy 
         */
		public static function getFileLoadProxy():FileLoadProxy
		{
			return FileLoadProxy( ApplicationFacade.getInstance().retrieveProxy( FileLoadProxy.NAME ) );
		}
		
		/**
         * Retrieve the File conversion proxy 
         */
		public static function getFileConvertProxy():FileConvertProxy
		{
			return FileConvertProxy( ApplicationFacade.getInstance().retrieveProxy( FileConvertProxy.NAME ) );
		}

		/**
         * Retrieve the Profile Controls  proxy 
         */
		public static function getProfileControlsProxy():ProfileControlsProxy {
			return ProfileControlsProxy( ApplicationFacade.getInstance().retrieveProxy( ProfileControlsProxy.NAME ) );
		}
		/**
		 * Start the application
		 */
		public function startup( app:CourseCreator ):void
		{
			application = app;
			//app.stage.scaleMode = StageScaleMode.NO_SCALE;
			sendNotification( STARTUP, app );
		}
		
    }
}